package com.budwk.app.waterquality.config;

import com.budwk.starter.common.exception.BaseException;
import com.budwk.starter.common.result.ResultCode;
import com.budwk.starter.security.utils.SecurityUtil;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * 全局异常处理器
 * 作用：异常代码可直接抛出该异常
 */
@Slf4j
@EqualsAndHashCode(callSuper = true)
public class AppException extends BaseException {

    private Integer code;

    public AppException() {
        super(ResultCode.SERVER_ERROR.getMsg());
        log.error("----------------------------AppException handleUserId: {}, handleUserName: {}, error: {}, ",
                SecurityUtil.getUserId(), SecurityUtil.getUserUsername(), ResultCode.SERVER_ERROR.getMsg());
    }

    public AppException(String message) {
        super(StringUtils.isNotEmpty(message) ? message : ResultCode.SERVER_ERROR.getMsg());
        log.error("----------------------------AppException error: {}, ", message);
    }

    public AppException(Integer code, String message) {
        super(message);
        this.code = code;
    }
}
